package com.nanhai.buddhist.college.module.collegebase.api.classes;

import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.module.collegebase.api.collegeclass.CollegeClassApi;
import com.nanhai.buddhist.college.module.collegebase.api.collegeclass.dto.ClassesBaseInfoDTO;
import com.nanhai.buddhist.college.module.collegebase.api.collegeclass.dto.ClassesInfoDTO;
import com.nanhai.buddhist.college.module.collegebase.api.collegeclass.dto.ClassesParentInfoDTO;
import com.nanhai.buddhist.college.module.collegebase.api.collegeclass.dto.ClassesRespDTO;
import com.nanhai.buddhist.college.module.collegebase.api.collegeclass.vo.ClassesInfoDTOPageVO;
import com.nanhai.buddhist.college.module.collegebase.convert.classes.ClassesConvert;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.classes.ClassesDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.classes.ClassesInfoDO;
import com.nanhai.buddhist.college.module.collegebase.service.classes.ClassesService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

import static com.nanhai.buddhist.college.module.collegebase.enums.ApiConstants.VERSION;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class CollegeClassApiImpl implements CollegeClassApi {

    @Resource
    private ClassesService classesService;

    @Override
    public CommonResult<List<ClassesRespDTO>> getClassesList(Collection<String> ids) {
        List<ClassesDO> classesList = classesService.getClassesList(ids);
        return CommonResult.success(ClassesConvert.INSTANCE.convertList03(classesList));
    }

    @Override
    public CommonResult<List<String>> getClassesByTeacher(String teacherId) {
        List<String> classesList = classesService.getClassesByTeacherId(teacherId);
        return CommonResult.success(classesList);
    }

    @Override
    public CommonResult<ClassesInfoDTO> getClassesInfoDTOById(String classesId) {
        ClassesDO classesDO = classesService.getClassesInfoDTOById(classesId);
        return CommonResult.success(ClassesConvert.INSTANCE.convertInfoDTO(classesDO));
    }

    @Override
    public CommonResult<List<ClassesInfoDTO>> getClassesInfoDTOListByTeacher(String teacherId) {
        List<ClassesDO> classesDOS = classesService.getClassesInfoDTOListByTeacher(teacherId);
        return CommonResult.success(ClassesConvert.INSTANCE.convertInfoDTOList(classesDOS));
    }

    @Override
    public CommonResult<PageResult<ClassesInfoDTO>> getClassesInfoDTOPageByTeacher(ClassesInfoDTOPageVO req) {
        PageResult<ClassesDO> pageResult = classesService.getClassesInfoDTOPageByTeacher(req);
        return CommonResult.success(ClassesConvert.INSTANCE.convertClassesInfoDTOPage(pageResult));
    }

    @Override
    public CommonResult<List<ClassesParentInfoDTO>> getClassesParentInfoDTOByClassesIds(Collection<String> classesIds) {
        List<ClassesInfoDO> classesInfoDOS = classesService.selectClassBaseInfoByClassesId(classesIds);
        return CommonResult.success(ClassesConvert.INSTANCE.convertParentInfoDTO(classesInfoDOS));
    }

    @Override
    public CommonResult<ClassesParentInfoDTO> getClassesParentInfoDTOByClassesId(String id) {
        ClassesInfoDO classesInfoDO = classesService.getClassesParentInfoDTOByClassesId(id);
        return CommonResult.success(ClassesConvert.INSTANCE.convertParentInfoDTOOne(classesInfoDO));
    }


    @Override
    public CommonResult<List<ClassesBaseInfoDTO>> selectClassBaseInfoByCollegeIds(Collection<String> collegeIds) {
        List<ClassesInfoDO> classesInfoDOS = classesService.selectClassesInfoByCollege(collegeIds);
        return CommonResult.success(ClassesConvert.INSTANCE.convertBaseInfo2DTO(classesInfoDOS));
    }

    @Override
    public CommonResult<List<ClassesBaseInfoDTO>> selectClassBaseInfoByProfessionIds(Collection<String> professionIds) {
        List<ClassesInfoDO> classesInfoDOS = classesService.selectClassBaseInfoByProfessionIds(professionIds);
        return CommonResult.success(ClassesConvert.INSTANCE.convertBaseInfo2DTO(classesInfoDOS));
    }
}
